package com.limao.DBProvider;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import com.limao.DBDataClass.VrGoodsDataClass;
import com.limao.DbConnection.DbConnectionManager;

public class VrGoodsProvider {
	
	private static class DB_Adv_ProviderContainer {
		private static VrGoodsProvider instance = new VrGoodsProvider();
	}

	public static VrGoodsProvider getInstance() {
		return DB_Adv_ProviderContainer.instance;
	}
	
	// 初始化
	private VrGoodsProvider() {

	}
	
	
	private VrGoodsDataClass encapOrderData(ResultSet rs) throws Exception{
		
		VrGoodsDataClass orderData = new VrGoodsDataClass();
		
		orderData.vrgoodsid= rs.getString("vrgoodsid");
		orderData.vrgoodsname= rs.getString("vrgoodsname");
		orderData.state= rs.getString("state");
		orderData.price= rs.getString("price");
		return orderData;
		
	}

	
	public List<VrGoodsDataClass> Load_All_VrGoodsList() {
		
		ArrayList<VrGoodsDataClass> list = new ArrayList<VrGoodsDataClass>();
		
		Connection con = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		try {
			con = DbConnectionManager.getConnection();
			pstmt = con.prepareStatement("select * from vr_sys_goods order by state desc,vrgoodsid asc");
			rs = pstmt.executeQuery();
			int i=0;
			while (rs.next()) {
				i=i+1;
				VrGoodsDataClass tmp=encapOrderData(rs);
				tmp.sortvalue=i+"";
				list.add(tmp);
			}
		} catch (Exception e) {
			list.clear();
			e.printStackTrace();
		} finally {
			DbConnectionManager.closeConnection(rs, pstmt, con);
		}
		return list;

	}
}
